<?php

require_once('../util/consts.php');

function newCaptcha( &$code, &$cpfile ) {
  if(!$code)
    $code = substr(hash('md5', microtime()*mktime()), 5, 7);

  $image = imagecreate(130, 30);

  $black = imagecolorallocate($image, 0, 0, 0);
  $white = imagecolorallocate($image, 255, 255, 255);
  $line = imagecolorallocate($image, 124, 239, 239);

  imagefill($image, 0, 0, $white);

  imageline($image, 0, 0, 39, 29, $line);
  imageline($image, 40, 0, 64, 29, $line);

  imagestring($image, 5, 20, 10, $code, $black);

  if(!$cpfile)
    $cpfile = TMP_DIR . DIRECTORY_SEPARATOR . 'captcha' . DIRECTORY_SEPERATOR . 10000000*microtime() . '.png';

  $captcha = imagepng($image, $cpfile);
  imagedestroy($image);
  return true;
}

?>
